# Maintainer: Thore Bödecker <foxxx0@archlinux.org>
# Maintainer: Tim Meusel <tim@bastelfreak.de>

_gemname=msgpack
pkgname="ruby-${_gemname}"
pkgver=1.7.2
pkgrel=1
pkgdesc='MessagePack implementation for Ruby'
url='https://github.com/msgpack/msgpack-ruby'
arch=('loong64' 'x86_64')
license=('Apache')
depends=('ruby')
makedepends=('ruby-rdoc' 'ruby-rake' 'ruby-rake-compiler' 'ruby-yard' 'ruby-rspec' 'ruby-bundler' 'ruby-webrick' 'ruby-ruby_memcheck')
options=('!emptydirs')
source=("${url}/archive/v${pkgver}/${pkgname}-v${pkgver}.tar.gz")
sha256sums=('f92a6d2212f4c5b42c1ae19a9617902d2dbc666d144e6e23d074172b14f6871e')
sha512sums=('c7ecf8031644c87debf6fab7d6b358a80cccefe4c0c795695056e5e82b1138641a5b94ea05b2b6edf20de2621ac59c059dce6a627a254742fbca8f73f0110c10')

prepare() {
  cd "${_gemname}-ruby-${pkgver}"
  sed 's|git ls-files -z|find -print0|' -i "${_gemname}.gemspec"
  sed 's|~>|>=|g' -i Gemfile
}

build() {
  cd "${_gemname}-ruby-${pkgver}"
  rake compile
  rake build
  rake clean
}

check() {
  cd "${_gemname}-ruby-${pkgver}"
  rake spec
}

package() {
  cd "${_gemname}-ruby-${pkgver}"
  local _gemdir="$(gem env gemdir)"
  gem install \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "${pkgdir}/${_gemdir}" \
    --bindir "${pkgdir}/usr/bin"  \
    "pkg/${_gemname}-${pkgver}.gem"

  install -Dm 644 README.md -t "${pkgdir}/usr/share/doc/${pkgname}"
  install -Dm 644 LICENSE -t "${pkgdir}/usr/share/licenses/${pkgname}"

  rm -rf "${pkgdir}/${_gemdir}/doc/${_gemname}-${pkgver}/ri/ext"

  cd "${pkgdir}/${_gemdir}"
  rm -r cache gems/"${_gemname}-${pkgver}"/{ext,tmp,lib/*/*.so} \
    extensions/*/*/"${_gemname}-${pkgver}"/{mkmf.log,gem_make.out}
}

# vim: ts=2 sw=2 et:
